export function getPercentChartOption({ data = [] }) {
  const newData: any = []
  let total = 0
  data.forEach((d, index) => {
    const { value, name } = d
    newData.push(
      Object.assign(
        { value, name },
        {
          label: {
            show: (function() {
              if (index === 0) {
                return true
              } else {
                return false
              }
            })(),
            padding: [0, -60],
            lineHeight: 30,
            formatter: '{c|{c}}\n{b|{b}}',
            rich: {
              c: {
                color: '#fff',
                fontSize: 22,
                fontWeight: 500,
                fontFamily: 'PingFang Regular'
              },
              b: {
                color: '#fff',
                fontSize: 14,
                fontWeight: 400,
                fontFamily: 'PingFang Regular'
              }
            },
            position: 'outside'
          },
          labelLine: {
            length: 25,
            length2: 80,
            // minAngle: 90,
            // minTurnAngle: 90,
            // maxSurfaceAngle: 90,
            show: (function() {
              if (index === 0) {
                return true
              } else {
                return false
              }
            })()
          },
          emphasis: {
            labelLine: {
              show: true
            }
          }
        }
      )
    )
    total += value
  })
  return {
    color: ['#E4A746', '#E44660', '#25EFBD', '#21BAD6', '#FFFFFF', '#11A151'],
    animation: true,
    title: {
      text: total,
      subtext: '总数',
      itemGap: 8,
      textStyle: {
        color: '#FFFFFF',
        fontSize: 30,
        fontWeight: 500,
        fontFamily: 'PingFang Regular'
      },
      subtextStyle: {
        fontSize: 18,
        color: ['#FFFFFF']
      },
      x: 'center',
      y: '33%'
    },
    // tooltip: {
    //   show: true
    // },
    tooltip: {
      backgroundColor: 'rgba(255,255,255, 0)',
      borderColor: 'rgba(255,255,255, 0)',
      // show: false
      formatter: (params: any) => {
        let html = ''
        if (params.seriesIndex === 0) {
          /* eslint-disable */
          return (html += `<span 
            style='display:block; width:110px; height:26px; line-height: 23px; background: linear-gradient(to right, #22B3F0 0%,#0D4BC9 100%); color:#fff;fontWeight:500; fontFamily:PingFang Regular; fontSize:16px; border-radius: 13px;padding: 0 9px'>
            ${params.name} : ${params.value}人
            </span>`)
        } else {
          return ''
        }
      }
    },
    legend: [
      {
        icon: 'roundRect',
        data: data.slice(0, 3),
        // width: '50%',
        bottom: '15%',
        left: 'center',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        align: 'left',
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(3, 6),
        // width: '50%',
        bottom: '5%',
        left: '24.5%',
        itemGap: 23,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      }
    ],
    series: [
      {
        radius: ['50%', '57%'],
        center: ['50%', '45%'],
        type: 'pie',
        clockwise: true,
        // startAngle: -90,
        itemStyle: {
          normal: {
            borderWidth: 5,
            borderColor: '#0C192C'
          }
        },
        data: newData
      },
      {
        tooltip: {
          show: false
        },
        radius: ['44%', '50%'],
        center: ['50%', '45%'],
        type: 'pie',
        animation: false,
        hoverAnimation: false,
        labelLine: {
          show: false
        },
        data: [
          {
            value: 0,
            itemStyle: {
              color: '#0a3057'
            }
          }
        ]
      },
      {
        tooltip: {
          show: false
        },
        radius: ['0', '34%'],
        center: ['50%', '45%'],
        type: 'pie',
        animation: false,
        hoverAnimation: false,
        labelLine: {
          show: false
        },
        data: [
          {
            value: 0,
            itemStyle: {
              color: '#0b345e'
            }
          }
        ]
      }
    ]
  }
}
